<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList"%>
<%@ page import="javax.jdo.Query" %>
<%@ page import="appnode.Node" %>
<%@ page import="appnode.SearchNode" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="appnode.Interface" %>
<%@ page import="appnode.PMF" %>

<html>
	<head>
	<link rel="stylesheet" href="map.css" type="text/css" media="screen" title="mapcss"></link>
	<title>New message</title>
	</head>
	<body class="window">
	<div class="openwindow">
	<p>Send a message</p>
	<%
		String fromnode = request.getParameter("fromnode");
		String tonode = request.getParameter("tonode");
		String typeofmsg = request.getParameter("typeofmsg");
		String subject = request.getParameter("subject");
		String skey = request.getParameter("skey");
	%>
	<form name="input" action="addmsg" method="post">
	To node :
	<input type="hidden" name="fromnode" value="<%=fromnode%>"></input>
	<input type="hidden" name="typeofmsg" value="<%=typeofmsg%>"></input>
	<input type="hidden" name="skey" value="<%=skey%>"></input>
	<input type="hidden" name="msgform" value="msgform"></input>
	<select name="tonode"> 
	<% 
		
		List<Node> n = new ArrayList<Node>();
		List<String> s = new ArrayList<String>();
		if (typeofmsg.equals("newmsg")) {
			if (tonode.equals("")) {
				n = SearchNode.getNodes(fromnode);
			}
			else {
				n.add(SearchNode.getByName(tonode));
			}
			s.add("newlink");
			s.add("help");
		}
		else {
			n.add(SearchNode.getByName(tonode));
			s.add(subject);
		}
		
		for (int i=0;i<n.size();i++) {
	%>	
			<option value="<%=n.get(i).getNodename()%>"><%=n.get(i).getNodename()%></optional>
	<%	
		}	
	
	%>
	</select><p>
		
	Subject :
	<select name="subject"> 
	<%
		for (int i=0;i<s.size();i++) {
	%>

		<option value="<%=s.get(i)%>"><%=s.get(i)%></optional>
	<%
	}
	%>
	</select><p> 
		
	Message <br>
	<textarea name="content" rows="10" cols="50"></textarea>
	<p>
	<input type="submit" value="Send message"/>
	<input type="button" value="Cancel" onClick="self.close()"/>
	
	<%
		
	%>
	
	</form>
	</div>
  <body>
<html>